<template>
  <div class="platform-dropdown-container">
    <el-tabs v-model="activeName" @tab-click="handleClick">
      <el-tab-pane v-for="platform in platforms" :key="platform.code" :label="platform.name" :name="platform.code" />
    </el-tabs>
    <div class="platform-dropdown-body">
      <slot />
    </div>
  </div>
</template>

<script>
import { list } from '@/api/platform.js'

export default {
  name: 'PlatformDropdown',
  data() {
    return {
      platforms: [],
      activeName: null
    }
  },
  mounted() {
    list().then(rsp => {
      if (rsp.code === 200 && !!rsp.data) {
        this.platforms = rsp.data || []
        this.activeName = (this.platforms[0] || {}).code
        this.$emit('platformChange', this.activeName)
      }
    })
  },
  methods: {
    handleClick(tab, event) {
      this.activeName = tab.name
      this.$emit('platformChange', this.activeName)
    }
  }
}
</script>

<style lang="scss">
.platform-dropdown-container{
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  position: absolute;
  padding: 20px 20px 0;
  .el-tabs__header.is-top{
    margin: 0;
    height: 40px;
  }
  .platform-dropdown-body{
    position: relative;
    overflow: hidden;
    flex-grow: 1;
  }
}
</style>>
